package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.StrategyTheme;
import cn.wolfcode.wolf2w.query.StrategyQueryObject;
import cn.wolfcode.wolf2w.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.IStrategyThemeService;
import cn.wolfcode.wolf2w.util.JsonResult;
import cn.wolfcode.wolf2w.vo.DestCatalogVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping("/strategy")
public class StrategyController {

    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyThemeService strategyThemeService;


    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo") StrategyQueryObject qo){

        Page page = strategyService.query(qo);
        model.addAttribute("page",page);
        return "/strategy/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Strategy strategy){
        strategyService.saveOrUpdate(strategy);
        return JsonResult.success();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        strategyService.delete(id);

        return JsonResult.success();
    }

    @RequestMapping("/input")
    public String input(Model model,String id){
        //查询目的地以及目的地下面的攻略分类
        List<DestCatalogVO> catalogs = strategyCatalogService.queryCatalogByDest();
        //根据目的地分组查询攻略分类
        //List<DestCatalogVO> catalogs = strategyCatalogService.groupList();
        Strategy strategy = strategyService.find(id);
        //查询主题列表
        List<StrategyTheme> themes = strategyThemeService.findAll();
        model.addAttribute("catalogs",catalogs);
        model.addAttribute("themes",themes);
        model.addAttribute("strategy",strategy);
        return "/strategy/input";
    }

}
